package com.niiwoo.civet.trade.property;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * @author bincun
 * @date 2018-11-06 14:01
 */

@ConfigurationProperties(IfcertProperties.PREFIX)
public class IfcertProperties {
    public static final String PREFIX = "ifcert";

    @Setter
    @Getter
    private String apiEnv = "test";//上传环境，固定值test或production，否则报错
    @Setter
    @Getter
    private String apikey;
    @Setter
    @Getter
    private String sourceCode;
    @Setter
    @Getter
    private String version = "1.5";
    @Setter
    @Getter
    private boolean stock = true;//是否存量上传,true表示存量上报，为2019.3.1号之前的未结清数据


    private Api api = null;
    public Api activateApi(String apiEnv){
        if (api == null){
            api = new Api(apiEnv);
        }
        return api;
    }
    @Data
    public static class Api{
        private  String ENDPOINT1;// 用户
        private  String ENDPOINT2;// 散标
        private  String ENDPOINT5;// 散标状态
        private  String ENDPOINT10;// 还款计划
        private  String ENDPOINT3;// 产品信息
        private  String ENDPOINT8;// 产品散标配置
        private  String ENDPOINT9;// 债权信息
        private  String ENDPOINT4;// 交易流水

        public Api(String apiEnv){
            if ("test".equalsIgnoreCase(apiEnv)){
                 ENDPOINT1 = "https://api.ifcert.org.cn/p2p/userInfo/test";// 用户
                 ENDPOINT2 = "https://api.ifcert.org.cn/p2p/scatterInvest/test";// 散标
                 ENDPOINT5 = "https://api.ifcert.org.cn/p2p/status/test";// 散标状态
                 ENDPOINT10 = "https://api.ifcert.org.cn/p2p/repayPlan/test";// 还款计划
                 ENDPOINT3 = "https://api.ifcert.org.cn/p2p/finance/test";// 产品信息
                 ENDPOINT8 = "https://api.ifcert.org.cn/p2p/financeScatterConfig/test";// 产品散标配置
                 ENDPOINT9 = "https://api.ifcert.org.cn/p2p/creditor/test";// 债权信息
                 ENDPOINT4 = "https://api.ifcert.org.cn/p2p/transact/test";// 交易流水
            }else if ("production".equalsIgnoreCase(apiEnv)){
                ENDPOINT1 = "https://api.ifcert.org.cn/p2p/userInfo";// 用户
                ENDPOINT2 = "https://api.ifcert.org.cn/p2p/scatterInvest";// 散标
                ENDPOINT5 = "https://api.ifcert.org.cn/p2p/status";// 散标状态
                ENDPOINT10 = "https://api.ifcert.org.cn/p2p/repayPlan";// 还款计划
                ENDPOINT3 = "https://api.ifcert.org.cn/p2p/finance";// 产品信息
                ENDPOINT8 = "https://api.ifcert.org.cn/p2p/financeScatterConfig";// 产品散标配置
                ENDPOINT9 = "https://api.ifcert.org.cn/p2p/creditor";// 债权信息
                ENDPOINT4 = "https://api.ifcert.org.cn/p2p/transact";// 交易流水
            }else {
                throw new RuntimeException("配置API有误");
            }
        }


    }
}
